package com.engr.springbooteasypoi.thread;

import java.util.concurrent.*;

/**
 * @author : liuYanXin
 * @Description : 返回值线程
 * @Date : 2020-03-26
 */
public class CallableCls {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                3, 5, 10L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(5)
                , Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        Callable callable1 = new MyCallable("A");
        Callable callable2 = new MyCallable("B");
        Future future = poolExecutor.submit(callable1);
        Future future2 = poolExecutor.submit(callable2);
        System.out.println(future.get().toString());
        System.out.println(future2.get().toString());
        poolExecutor.shutdown();
    }
}

class MyCallable implements Callable {

    private String oid;

    public MyCallable(String oid) {
        this.oid = oid;
    }

    @Override
    public Object call() throws Exception {
        return oid + "返回任务";
    }
}
